package thread;

/**
 * 计算100以内奇数的和,偶数的和
 */
public class Test {
    public static void main(String[] args) {
        //Thread t1 = new Thread(()-> {for (int i = 1, sum = 0; i <= 100; System.out.println(sum += i), i += 2) {} });
        //t1.start();

        Thread t2 = new Thread(){
            @Override
            public void run(){
                for(int i=0,sum=0; i<=100; i+=2 ){
                    System.out.println(sum+=i);
                }
            }
        };
        t2.start();

        //同理把上式写成lambda
        Thread t3 = new Thread(() -> { for (int i = 0, sum = 0; i <= 100; System.out.println(sum += i), i += 2){} });
    }
}
